//
//  WPTradeOrderViewController.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/4/5.
//  Copyright © 2016年 WPJoe. All rights reserved.
//

#import "WPTradeOrderViewController.h"
#import "WPOrderDetailAlertView.h"
#import "WPTopupTopAlertView.h"
#import "WPPaySuccessAlertView.h"
#import "WPPayFailAlertView.h"
#import "WPTradeOrderPayViewModel.h"
#import "WPPlaceAnOrderAlertView.h"


static  NSString * const riskDetailText = @"1、本平台暂不支持线上付款，您在下单后需自行与项目方联系，协商取票事宜。\n2、1.2米以下儿童谢绝入场（儿童项目除外），1.2米以上儿童需持票入场。\n3、进入下单页后需在5分钟内完成下单，未成功下单的下单页，将在5分钟后系统自动取消下单渠道，所选门票将自动释放后重新进入交易列表，大家可及时刷新下单页页面进行下单。";

@interface WPTradeOrderViewController ()
@property (nonatomic, strong) UIScrollView * backScrollView;/**< 最下层滚动视图 */
@property (nonatomic, strong) UIView * whiteBackView;/**< 白色背景图 */
@property (nonatomic, strong) UIImageView * introImageView;
@property (nonatomic, strong) UILabel * titleLabel;/**< 标题文本 */
@property (nonatomic, strong) UILabel * nameLabel;/**< 发起人 */
@property (nonatomic, strong) UITextField * payTimeTextField;/**< 倒计时 */
@property (nonatomic, strong) NSTimer * timer;/**< 计时器 */
@property (nonatomic, assign) NSInteger timeCount;/**< 倒计时时间 */

@property (nonatomic, strong) UIView * payDetailView;/**< 支付详情背景图 */
@property (nonatomic, strong) UILabel * payMoneyIntroLabel;/**< 支付金额说明 */
@property (nonatomic, strong) UILabel * payMoneyCountLabel;/**< 支付金额 */
@property (nonatomic, strong) UITextField * receiveTextField;/**< 收款方 */
@property (nonatomic, strong) UITextField * payStyleTextField;/**< 支付方式 */

@property (nonatomic, strong) UIView * tradeRightView;/**< 交易权益 */
@property (nonatomic, strong) UILabel * tradeTitleLabel;/**< 交易标题 */
@property (nonatomic, strong) UILabel * timeLabel;/**< 演出时间 */
@property (nonatomic, strong) UILabel * addressLabel;/**< 演出地点 */
@property (nonatomic, strong) UILabel * positionLabel;/**< 票对应位置 */

@property (nonatomic, strong) UIView * riskView;/**< 风险提示背景图 */
@property (nonatomic, strong) UITextView * riskTextView;/**< 风险提示文本 */
@property (nonatomic, strong) UIButton * spreadBtn;/**< 展开收起按钮 */
@property (nonatomic, strong) UIButton * payBtn;/**< 支付按钮 */
@property (nonatomic, strong) UIBezierPath * path;/**< 贝塞尔曲线 */
@property (nonatomic, strong) CAShapeLayer * shapeLayer;/**< 画笔 */

- (void)initializeDataSource; /**< 初始化数据源 */
- (void)initializeUserInterface; /**< 初始化用户界面 */
- (void)addLineWithStartPoint:(CGPoint)start andWithEndPoint:(CGPoint)end;/**< 画线 */

@end

@implementation WPTradeOrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeDataSource];
    [self initializeUserInterface];
}
#pragma mark - init
- (void)initializeDataSource {
    self.timeCount = 60*10;
}
- (void)initializeUserInterface {
    self.title = @"订单详情";
    [self.view addSubview:self.backScrollView];
    [_backScrollView addSubview:self.whiteBackView];
    [_whiteBackView addSubview:self.introImageView];
    [_whiteBackView addSubview:self.titleLabel];
    [_whiteBackView addSubview:self.nameLabel];
    [self addLineWithStartPoint:CGPointMake(0, CGRectGetMaxY(self.introImageView.frame)) andWithEndPoint:CGPointMake(0, CGRectGetMaxY(self.nameLabel.frame))];
    [self addLineWithStartPoint:CGPointMake(0, CGRectGetMaxY(self.nameLabel.frame)) andWithEndPoint:CGPointMake(CGRectGetMaxX(self.introImageView.frame), CGRectGetMaxY(self.nameLabel.frame))];
    [self addLineWithStartPoint:CGPointMake(CGRectGetMaxX(self.introImageView.frame), CGRectGetMaxY(self.nameLabel.frame)) andWithEndPoint:CGPointMake(CGRectGetMaxX(self.introImageView.frame), CGRectGetMaxY(self.introImageView.frame))];
//    [_whiteBackView addSubview:self.payTimeTextField];
    [self configGrayViewWithPositionY:CGRectGetMaxY(_nameLabel.frame)];

    [_whiteBackView addSubview:self.payDetailView];
    [self configGrayViewWithPositionY:CGRectGetMaxY(_payDetailView.frame)];
    [_whiteBackView addSubview:self.tradeRightView];
    [self configGrayViewWithPositionY:CGRectGetMaxY(_tradeRightView.frame)];
    [_whiteBackView addSubview:self.riskView];
    [_backScrollView addSubview:self.payBtn];
    [_backScrollView.layer addSublayer:self.shapeLayer];
}
#pragma mark - responds events
- (void)respondsToTimer {
    _timeCount--;
    NSInteger currentSeconds = _timeCount % 60;
    NSInteger currentMinutes = (_timeCount / 60) %60;
    NSString *stingFormat = @"支付剩余时间：%d分钟%d秒" ;
    self.payTimeTextField.text = [NSString stringWithFormat:stingFormat, currentMinutes, currentSeconds];
}
- (void)respondsToSpreadBtn:(UIButton *)sender {
    
}
- (void)respondsToPayBtn:(UIButton *)sender {
//    if ([[UserModel defaultUser].balance floatValue] < [_payMoneyCountLabel.text floatValue]) {
//        [self topupTopAlertView];
//        return;
//    }
    if ([[UserModel defaultUser].phoneNumber isEqualToString:_model.salePersonName]) {
        [self initializeAlertControllerWithMessageAndDismiss:@"您不能买入你自己的票"];
        return;
    }
    if (![UserModel defaultUser].needAutoLogin) {
        [self presentToLoginViewController];
        return;
    }
    MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.removeFromSuperViewOnHide = YES;
    hud.color = [UIColor lightGrayColor];
    hud.labelText = @"请稍候";
    hud.detailsLabelText = @"提交订单中...";
    __weak typeof(self)weakself = self;
    [WPTradeOrderPayViewModel payOrderWithTicketId:_model.ticketId  pwd:@"" andSuccessBlock:^(NSString *suc) {
        NSArray * result = [suc componentsSeparatedByString:@","];
        sender.backgroundColor = COLOR_RGB(234, 27, 47, 1);
//    NSArray * result = @[@"1231", @"3456"];
        [WPPlaceAnOrderAlertView showViewWithSize:CGRectMake(25*DHFlexibleHorizontalMutiplier(), 110*DHFlexibleVerticalMutiplier(), 270*DHFlexibleVerticalMutiplier(), 210*DHFlexibleHorizontalMutiplier()) andWithContactName:result[0] andWithContactPhone:result[1] WithComplete:^(NSString *result) {
            if ([result isEqualToString:@"back"]) {
                [weakself.navigationController popViewControllerAnimated:YES];
            } else {
                [weakself pushToNextController:[[NSClassFromString(@"WPOrderViewController") alloc]init]  withVCTitle:@"我的订单"];
            }
        }];
    } andFailureBlock:^(NSString *fail) {
        hud.labelText = @"下单失败";
        hud.detailsLabelText = fail;
        [hud hide:YES afterDelay:2.0];
    } ];
    
//    [self walletPay];
}
#pragma mark - private methods
- (NSMutableAttributedString *)configPayCountWithCount:(NSString *)count {
    NSMutableAttributedString * attributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@元", count]];
    [attributedStr addAttribute:NSForegroundColorAttributeName value:COLOR_RGB(234, 27, 47, 1) range:NSMakeRange(0, count.length)];
    [attributedStr addAttribute:NSForegroundColorAttributeName value:COLOR_RGB(61, 61, 61, 1) range:NSMakeRange(attributedStr.length - 1, 1)];
    [attributedStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:22*DHFlexibleHorizontalMutiplier()] range:NSMakeRange(0 , count.length)];
    [attributedStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()] range:NSMakeRange(attributedStr.length -1 , 1)];
    
    return attributedStr;
}
- (void)addLineWithStartPoint:(CGPoint)start andWithEndPoint:(CGPoint)end {
    [self.path moveToPoint:start];
    [self.path addLineToPoint:end];
}
#pragma mark - 订单信息弹出框
- (void)popOrderDetailAlertView {
    __weak typeof(self)weakself = self;
    [WPOrderDetailAlertView showViewWithSize:CGRectMake(20*DHFlexibleHorizontalMutiplier(), 110*DHFlexibleHorizontalMutiplier(), 270*DHFlexibleHorizontalMutiplier(), 220*DHFlexibleHorizontalMutiplier()) andWithTitle:@"付款详情" andWithOrderInfo:@"今天必须给钱" andWithOrderMoenyCount:@"1400元" WithComplete:^(NSString *result) {
        NSInteger count = arc4random()+3;
        if (count%2) {
            [weakself topupTopAlertView];
            return;
        }
        [weakself walletPay];
    }];
}
#pragma mark - 支付键盘弹出框

#pragma mark - 充值提醒
- (void)topupTopAlertView {
    __weak typeof(self)weakself = self;
    [WPTopupTopAlertView showViewWithSize:CGRectMake(20*DHFlexibleHorizontalMutiplier(), 110*DHFlexibleHorizontalMutiplier(), 270*DHFlexibleHorizontalMutiplier(), 190*DHFlexibleHorizontalMutiplier()) andWithTitle:@"充值提醒" andWithBalance:@"400" WithComplete:^(NSString *result) {
        [weakself pushToNextController:[[NSClassFromString(@"WPTopupViewController") alloc]init] withVCTitle:@"充值"];
    }];
}
#pragma mark - 键盘弹出支付
- (void)walletPay {
    __weak typeof(self)weakself = self;
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle:_detailModel.name message:_tradeTitleLabel.text preferredStyle:UIAlertControllerStyleAlert];
    [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        textField.placeholder = @"请输入提现密码";
        textField.clearButtonMode = UITextFieldViewModeWhileEditing;
        textField.secureTextEntry = YES;
    }];
    [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
    [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSString * wpwd = [alertController textFields].firstObject.text;
        if (wpwd.length == 0) {
            [weakself initializeAlertControllerWithMessage:@"请输入提现密码"];
        } else {
            MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
            hud.removeFromSuperViewOnHide = YES;
            hud.color = [UIColor grayColor];
            hud.labelText = @"请稍候";
            hud.detailsLabelText = @"正在支付中...";
            [WPTradeOrderPayViewModel payOrderWithTicketId:_model.ticketId pwd:wpwd andSuccessBlock:^(NSString *suc) {
                [weakself paySuccessAlertView];
            } andFailureBlock:^(NSString *fail) {
                [weakself payFailAlertViewWithFail:fail];
            }];
        }
    }]];
    [self presentViewController:alertController animated:YES completion:nil];
}
#pragma mark - 支付成功弹出框
- (void)paySuccessAlertView {
    __weak typeof(self)weakself = self;
    [WPPaySuccessAlertView showViewWithSize:CGRectMake(20*DHFlexibleHorizontalMutiplier(), 110*DHFlexibleHorizontalMutiplier(), 270*DHFlexibleHorizontalMutiplier(), 300*DHFlexibleHorizontalMutiplier()) andWithDetail:@"FAFA" WithComplete:^(NSString *result) {
        [weakself pushToNextController:[[NSClassFromString(@"") alloc] init] withVCTitle:@"我的权益"];
    }];
}
- (void)payFailAlertViewWithFail:(NSString *)fail {
    __weak typeof(self)weakself = self;
    [WPPayFailAlertView showViewWithSize:CGRectMake(20*DHFlexibleHorizontalMutiplier(), 110*DHFlexibleHorizontalMutiplier(), 270*DHFlexibleHorizontalMutiplier(), 120*DHFlexibleHorizontalMutiplier()) andWithDetail:fail WithComplete:^(NSString *result) {
        [weakself walletPay];
    }];
}
- (void)configGrayViewWithPositionY:(CGFloat)y {
    UIView * grayView = [[UIView alloc]initWithFrame:CGRectMake(0, y, 310*DHFlexibleHorizontalMutiplier(), 12*DHFlexibleHorizontalMutiplier())];
    grayView.backgroundColor = COLOR_RGB(241, 241, 241, 1);
    [_whiteBackView addSubview:grayView];
}
- (NSMutableAttributedString *)configAttributtedStringWithString:(NSString *)str {
    NSMutableAttributedString * attributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@元", str]];
    [attributedStr addAttribute:NSForegroundColorAttributeName value:COLOR_RGB(242, 106, 89, 1) range:NSMakeRange(0, str.length)];
    [attributedStr addAttribute:NSForegroundColorAttributeName value:COLOR_RGB(141, 141, 141, 1) range:NSMakeRange(str.length, 1)];
    return attributedStr;
}
#pragma mark - getter
- (UIScrollView *)backScrollView {
    if (!_backScrollView) {
        _backScrollView = ({
            UIScrollView * view = [[UIScrollView alloc]initWithFrame:CGRectMake(7*DHFlexibleHorizontalMutiplier(), navBar_Fheight+10*DHFlexibleHorizontalMutiplier(), 306*DHFlexibleHorizontalMutiplier(), SCREEN_SIZE.height - navBar_Fheight-10*DHFlexibleHorizontalMutiplier())];
            view.contentSize = CGSizeMake(0, CGRectGetMaxY(self.whiteBackView.frame)+90*DHFlexibleHorizontalMutiplier());
            view;
        });
    }
    return _backScrollView;
}
- (UIView *)whiteBackView {
    if (!_whiteBackView) {
        _whiteBackView = ({
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 306*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.riskView.frame))];
            view.backgroundColor = [UIColor whiteColor];
            view.layer.cornerRadius = 3*DHFlexibleHorizontalMutiplier();
            view.layer.masksToBounds = YES;
            view;
        });
    }
    return _whiteBackView;
}
- (UIImageView *)introImageView {
    if (!_introImageView) {
        _introImageView = ({
            UIImageView * view = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 306*DHFlexibleHorizontalMutiplier(), 155*DHFlexibleHorizontalMutiplier())];
            view.image = IMAGE_NAME(@"image3");
            view;
        });
    }
    return _introImageView;
}
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(5*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.introImageView.frame), 300*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            lab.textColor = COLOR_RGB(61, 61, 61, 1);
            lab.font = [UIFont systemFontOfSize:13*DHFlexibleHorizontalMutiplier()];
            lab.text = _detailModel.name;
            lab;
        });
    }
    return _titleLabel;
}
- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(5*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.titleLabel.frame)-10*DHFlexibleHorizontalMutiplier(), 300*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            lab.textColor = [UIColor colorWithHexString:@"#666666"];
            lab.font = [UIFont systemFontOfSize:11*DHFlexibleHorizontalMutiplier()];
            if (_model.salePersonName.length == 11) {
                lab.text = [NSString stringWithFormat:@"%@****%@", [_model.salePersonName substringToIndex:3], [_model.salePersonName substringWithRange:NSMakeRange(7, 4)]];
            } else {
                lab.text = _model.salePersonName;
            }
            lab;
        });
    }
    return _nameLabel;
}
- (UITextField *)payTimeTextField {
    if (!_payTimeTextField) {
        _payTimeTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.nameLabel.frame), 306*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            text.leftViewMode = UITextFieldViewModeAlways;
            UIView * leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 86*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(63*DHFlexibleHorizontalMutiplier(), 9*DHFlexibleHorizontalMutiplier(), 12*DHFlexibleHorizontalMutiplier(), 12*DHFlexibleHorizontalMutiplier())];
            imageView.image = IMAGE_NAME(@"djs");
            [leftView addSubview:imageView];
            text.leftView = leftView;
            text.backgroundColor = COLOR_RGB(241, 241, 241, 1);
            text.textColor = COLOR_RGB(234, 27, 47, 1);
            text.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            text.userInteractionEnabled = NO;
            text;
        });
    }
    return _payTimeTextField;
}
- (NSTimer *)timer {
    if (!_timer) {
        _timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(respondsToTimer) userInfo:nil repeats:YES];
    }
    return _timer;
}

- (UIView *)payDetailView {
    if (!_payDetailView) {
        _payDetailView = ({
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.nameLabel.frame)+12*DHFlexibleHorizontalMutiplier(), 310*DHFlexibleHorizontalMutiplier(), 170*DHFlexibleHorizontalMutiplier())];
            UILabel * title = [[UILabel alloc]initWithFrame:CGRectMake(10*DHFlexibleHorizontalMutiplier(), 0, 300, 30*DHFlexibleHorizontalMutiplier())];
            title.textColor = [UIColor colorWithHexString:@"#666666"];
            title.font = [UIFont boldSystemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            title.text = @"支付详情";
            UIView * line = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(title.frame), 310*DHFlexibleHorizontalMutiplier(), 0.5)];
            line.backgroundColor = COLOR_RGB(191, 191, 191, 1);
            [view addSubview:line];
            [view addSubview:title];
            [view addSubview:self.payMoneyIntroLabel];
            [view addSubview:self.payMoneyCountLabel];
            [view addSubview:self.receiveTextField];
            [view addSubview:self.payStyleTextField];
            view;
        });
    }
    return _payDetailView;
}
- (UILabel *)payMoneyIntroLabel {
    if (!_payMoneyIntroLabel) {
        _payMoneyIntroLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 40*DHFlexibleHorizontalMutiplier(), 310*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            lab.textAlignment = NSTextAlignmentCenter;
            lab.textColor = [UIColor colorWithHexString:@"#666666"];
            lab.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            lab.text = @"付款金额";
            lab;
        });
    }
    return _payMoneyIntroLabel;
}
- (UILabel *)payMoneyCountLabel {
    if (!_payMoneyCountLabel) {
        _payMoneyCountLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.payMoneyIntroLabel.frame), 310*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            lab.textAlignment = NSTextAlignmentCenter;
            lab.font = [UIFont systemFontOfSize:22*DHFlexibleHorizontalMutiplier()];
            lab.attributedText = [self configPayCountWithCount:[NSString stringWithFormat:@"%@", _model.salePrice]];
            lab;
        });
    }
    return _payMoneyCountLabel;
}
- (UITextField *)payStyleTextField {
    if (!_payStyleTextField) {
        _payStyleTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(10*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.payMoneyCountLabel.frame)+30*DHFlexibleHorizontalMutiplier(), 286*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            text.leftViewMode = UITextFieldViewModeAlways;
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30*DHFlexibleHorizontalMutiplier())];
            lab.textColor = [UIColor colorWithHexString:@"#666666"];
            lab.font = [UIFont boldSystemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            lab.text = @"支付方式";
            text.leftView = lab;
            text.font = [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            text.textColor = [UIColor colorWithHexString:@"#3d3d3d"];
            text.textAlignment = NSTextAlignmentRight;
            text.userInteractionEnabled = NO;
            text.text = @"货到付款";
            text;
        });
    }
    return _payStyleTextField;
}
- (UITextField *)receiveTextField {
    if (!_receiveTextField) {
        _receiveTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(10*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.payStyleTextField.frame), 286*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            text.leftViewMode = UITextFieldViewModeAlways;
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30*DHFlexibleHorizontalMutiplier())];
            lab.textColor = [UIColor colorWithHexString:@"#666666"];
            lab.font = [UIFont boldSystemFontOfSize:13*DHFlexibleHorizontalMutiplier()];
            lab.text = @"收款方";
            text.leftView = lab;
            text.font = [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            text.textColor = [UIColor colorWithHexString:@"#3d3d3d"];
            text.textAlignment = NSTextAlignmentRight;
            text.userInteractionEnabled = NO;
            text.text = @"项目方";
            text;
        });
    }
    return _receiveTextField;
}
- (UIView *)tradeRightView {
    if (!_tradeRightView) {
        _tradeRightView = ({
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.payDetailView.frame)+12*DHFlexibleHorizontalMutiplier(), 310*DHFlexibleHorizontalMutiplier(), 180*DHFlexibleHorizontalMutiplier())];
            UILabel * title = [[UILabel alloc]initWithFrame:CGRectMake(10*DHFlexibleHorizontalMutiplier(), 0, 300, 30*DHFlexibleHorizontalMutiplier())];
            title.textColor = [UIColor colorWithHexString:@"#666666"];
            title.font = [UIFont boldSystemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            title.text = @"交易权益";
            UIView * line = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(title.frame), 310*DHFlexibleHorizontalMutiplier(), 0.5)];
            line.backgroundColor = COLOR_RGB(191, 191, 191, 1);
            [view addSubview:line];
            [view addSubview:title];
            [view addSubview:self.tradeTitleLabel];
            [view addSubview:self.timeLabel];
            [view addSubview:self.addressLabel];
            [view addSubview:self.positionLabel];
            view;
        });
    }
    return _tradeRightView;
}
- (UILabel *)tradeTitleLabel {
    if (!_tradeTitleLabel) {
        _tradeTitleLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(10*DHFlexibleHorizontalMutiplier(), 35*DHFlexibleHorizontalMutiplier(), 280*DHFlexibleHorizontalMutiplier(), 60*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:15*DHFlexibleHorizontalMutiplier()];
            lab.textColor = [UIColor colorWithHexString:@"#666666"];
            lab.numberOfLines = 0;
            lab.text = _detailModel.name;
            lab;
        });
    }
    return _tradeTitleLabel;
}
- (UILabel *)timeLabel {
    if (!_timeLabel) {
        _timeLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(10*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.tradeTitleLabel.frame), 280*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:13*DHFlexibleHorizontalMutiplier()];
            lab.textColor = [UIColor colorWithHexString:@"#666666"];
            lab.text = @"4月23日 星期六20：00 ~ 22：00";
            lab;
        });
    }
    return _timeLabel;
}
- (UILabel *)addressLabel {
    if (!_addressLabel) {
        _addressLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(10*DHFlexibleHorizontalMutiplier(), 130*DHFlexibleHorizontalMutiplier(), 280*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:13*DHFlexibleHorizontalMutiplier()];
            lab.textColor = [UIColor colorWithHexString:@"#666666"];
            lab.text = @"成都体育馆(人民南路四段8号)";
            lab;

        });
    }
    return _addressLabel;
}
- (UILabel *)positionLabel {
    if (!_positionLabel) {
        _positionLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(10*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.addressLabel.frame), 300, 30*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:13*DHFlexibleHorizontalMutiplier()];
            lab.textColor = [UIColor colorWithHexString:@"#666666"];
            lab.text = _model.ticketName;
            lab;

        });
    }
    return _positionLabel;
}
- (UIView *)riskView {
    if (!_riskView) {
        _riskView = ({
            CGRect rect = [WPCalculateRectHandle calculateSizeWithFont:13*DHFlexibleHorizontalMutiplier() Text:riskDetailText Width:290*DHFlexibleHorizontalMutiplier()];
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.tradeRightView.frame)+12*DHFlexibleHorizontalMutiplier(), 310*DHFlexibleHorizontalMutiplier(), 5*DHFlexibleHorizontalMutiplier()+rect.size.height*2+50*DHFlexibleHorizontalMutiplier())];
            UILabel * title = [[UILabel alloc]initWithFrame:CGRectMake(10*DHFlexibleHorizontalMutiplier(), 0, 300, 30*DHFlexibleHorizontalMutiplier())];
            title.textColor = [UIColor colorWithHexString:@"#666666"];
            title.font = [UIFont boldSystemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            title.text = @"购买说明";
            UIView * line = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(title.frame), 310*DHFlexibleHorizontalMutiplier(), 0.5)];
            line.backgroundColor = COLOR_RGB(191, 191, 191, 1);
            [view addSubview:line];
            [view addSubview:title];
            [view addSubview:self.riskTextView];
//            [view addSubview:self.spreadBtn];
            view;
        });
    }
    return _riskView;
}
- (UITextView *)riskTextView {
    if (!_riskTextView) {
        _riskTextView = ({
            NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:riskDetailText];
            NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
            paragraphStyle.lineSpacing = 10;
            [attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15*DHFlexibleHorizontalMutiplier()] range:NSMakeRange(0, attributedString.length)];
            [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#3d3d3d"] range:NSMakeRange(0, attributedString.length)];
            [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, riskDetailText.length)];
            CGRect rect = [WPCalculateRectHandle calculateSizeWithFont:13*DHFlexibleHorizontalMutiplier() Text:riskDetailText Width:290*DHFlexibleHorizontalMutiplier()];
            UITextView * text = [[UITextView alloc]initWithFrame:CGRectMake(10*DHFlexibleHorizontalMutiplier(), 35*DHFlexibleHorizontalMutiplier(), 290*DHFlexibleHorizontalMutiplier(), rect.size.height*3)];
            text.textColor = [UIColor colorWithHexString:@"#666666"];
            text.editable = NO;
            text.scrollEnabled = NO;
            text.attributedText = attributedString;
            text;
        });
    }
    return _riskTextView;
}
- (UIButton *)spreadBtn {
    if (!_spreadBtn) {
        _spreadBtn = ({
            UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(230*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.riskTextView.frame)- 30*DHFlexibleHorizontalMutiplier(), 55*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier());
            [btn setTitle:@"展开V" forState:UIControlStateNormal];
            [btn setTitle:@"收起^" forState:UIControlStateSelected];
            [btn addTarget:self action:@selector(respondsToSpreadBtn:) forControlEvents:UIControlEventTouchUpInside];
            btn.backgroundColor = COLOR_RGB(241, 241, 241, 241);
            btn;
        });
    }
    return _spreadBtn;
}
- (UIButton *)payBtn {
    if (!_payBtn) {
        _payBtn = ({
            UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(10*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.whiteBackView.frame)+30*DHFlexibleHorizontalMutiplier(), 280*DHFlexibleHorizontalMutiplier(), 35*DHFlexibleHorizontalMutiplier());
            btn.backgroundColor = COLOR_RGB(234, 27, 47, 1);
            btn.layer.cornerRadius = 15*DHFlexibleHorizontalMutiplier();
            btn.titleLabel.font = [UIFont boldSystemFontOfSize:15*DHFlexibleHorizontalMutiplier()];
            [btn setTitle:@"立即下单" forState:UIControlStateNormal];
            [btn addTarget:self action:@selector(respondsToPayBtn:) forControlEvents:UIControlEventTouchUpInside];
            btn;
        });
    }
    return _payBtn;
}
- (UIBezierPath *)path {
    if (!_path) {
        _path = [UIBezierPath bezierPath];
    }
    return _path;
}
- (CAShapeLayer *)shapeLayer {
    if (!_shapeLayer) {
        _shapeLayer = ({
            CAShapeLayer * layer = [CAShapeLayer layer];
            layer.frame = DHFlexibleFrame(CGRectMake(0, 0, 320, 800), NO);
            layer.fillColor = [UIColor whiteColor].CGColor;
            layer.backgroundColor = [UIColor clearColor].CGColor;
            layer.strokeColor = COLOR_RGB(210, 211, 212, 1).CGColor;/**< 画笔颜色 */
            layer.path = self.path.CGPath;
            layer.lineWidth = 0.5;
            layer;
        });
    }
    return _shapeLayer;
}
@end
